//
//  SAStatisticsManagementHeaderView.m
//  saasRetail
//
//  Created by 黄志刚 on 2021/7/22.
//

#import "SAStatisticsManagementHeaderView.h"
#import "SAStatisticsManagementModel.h"

@interface SAStatisticsManagementHeaderView ()

@property (nonatomic, strong) UIView *whiteView;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *numLab;
@property (nonatomic, strong) UILabel *priceLab;
@property (nonatomic, strong) UIView *line;
@property (nonatomic, strong) UIImageView *imageV;

@end

@implementation SAStatisticsManagementHeaderView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        [self initUI];
    }
    return self;
}

-(void)setModel:(SAStatisticsManagementModel *)model {
    _model = model;
    self.titleLab.text = model.empName;
    self.numLab.text = [NSString stringWithFormat:@"实销数:%@",model.actualCount];
    self.priceLab.text = [NSString stringWithFormat:@"实销额:%0.2lf",[model.actualPrice doubleValue]/100.f];
    if (model.isOpen == YES) {
        _imageV.image = [UIImage imageNamed:@"SA_arrow_up"];
    }else {
        _imageV.image = [UIImage imageNamed:@"SA_arrow_down"];
    }
}

-(void)clickedTap {
    !self.selectBlock ?: self.selectBlock();
}

-(void)initUI {
    [self.contentView addSubview:self.whiteView];
    [self.contentView addSubview:self.titleLab];
    [self.contentView addSubview:self.numLab];
    [self.contentView addSubview:self.priceLab];
    [self.contentView addSubview:self.line];
    [self.contentView addSubview:self.imageV];
}

-(UIView *)whiteView {
    if (!_whiteView) {
        _whiteView = [[UIView alloc] initWithFrame:SARectMake(0, 0, kBaseScreenWidth, 50)];
        _whiteView.backgroundColor = [UIColor whiteColor];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickedTap)];
        [_whiteView addGestureRecognizer:tap];
    }
    return _whiteView;
}

-(UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] initWithFrame:SARectMake(30, 0, 80, 50)];
        _titleLab.textColor = kBlackColor;
        _titleLab.font = kFont(15);
    }
    return _titleLab;
}

-(UILabel *)numLab {
    if (!_numLab) {
        _numLab = [[UILabel alloc] initWithFrame:SARectMake(120, 0, 100, 50)];
        _numLab.textColor = kBlackColor;
        _numLab.font = kFont(15);
        _numLab.textAlignment = NSTextAlignmentLeft;
    }
    return _numLab;
}

-(UILabel *)priceLab {
    if (!_priceLab) {
        _priceLab = [[UILabel alloc] initWithFrame:CGRectMake(kScaleNum(225), 0, kScaleNum(122), kScaleNum(50))];
        _priceLab.textColor = kBlackColor;
        _priceLab.font = kFont(15);
        _priceLab.textAlignment = NSTextAlignmentLeft;
    }
    return _priceLab;
}

-(UIImageView *)imageV {
    if (!_imageV) {
        _imageV = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenWidth - kScaleNum(30), kScaleNum(20), kScaleNum(18), kScaleNum(10))];
        _imageV.image = [UIImage imageNamed:@"SA_arrow_up"];
    }
    return _imageV;
}

-(UIView *)line {
    if (!_line) {
        _line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScaleNum(0.5))];
        _line.backgroundColor = kLineColor;
    }
    return _line;
}

@end
